﻿//https://leetcode.cn/problems/best-time-to-buy-and-sell-stock/

class Solution {
public:
    int maxProfit(vector<int>& prices)
    {
        int n = prices.size();
        int prevmin = prices[0];
        int ret = 0;

        for (int i = 1; i < n; i++)
        {
            //更新结果
            ret = max(ret, prices[i] - prevmin);

            //更新最小值
            prevmin = min(prevmin, prices[i]);

        }

        return ret;

    }
};